@extends('user.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('user.layouts.navbar')
        @include('user.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item"><a href="{{ route('promotion.index') }}">我的推广</a></li>
                                <li class="breadcrumb-item active" aria-current="page">编辑</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                                <div class="row">
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>跳转地址：</label>
                                            <input type="text" class="form-control" id="url" value="{{$item[0]->url}}"
                                                   maxlength="50">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>单价/次：</label>
                                            <input type="text" class="form-control" id="single"
                                                   value="{{$item[0]->single}}" maxlength="8">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>增加额度：</label>
                                            <input type="text" class="form-control" id="total"
                                                   placeholder="当前额度：{{$item[0]->total}}元" maxlength="8">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>状态：</label>
                                            <select class="form-control" id="state">
                                                <option value=""> 请选择状态</option>
                                                <option value="1" {{$item[0]->state ? 'selected':''}}>上架</option>
                                                <option value="0" {{$item[0]->state ? '':'selected'}}>下架</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>开始时间：</label>
                                            <input type="date" class="form-control" id="start_date"
                                                   value="{{$item[0]->start_date}}" maxlength="11">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <label>结束时间：</label>
                                            <input type="date" class="form-control" id="end_date"
                                                   value="{{$item[0]->end_date}}" maxlength="11">
                                        </div>
                                    </div>
                                    <div class="col-lg-5">
                                        <div class="form-group">
                                            <button class="btn btn-primary" onclick="operation_tip2({{$item[0]->id}})">提交
                                            </button>
                                        </div>
                                    </div>

                                </div> <!-- .row -->
                            </div> <!-- .card-body -->
                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->
    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>

        let isLoading = false;

        //提交
        function submit(id) {

            if (!$('#url').val()) {
                toast('推广的链接 不能为空');
                return false
            }
            if (!$('#single').val()) {
                toast('单价 不能为空。');
                return false
            }
            if (!$('#state').val()) {
                toast('状态 不能为空。');
                return false
            }
            if (!$('#start_date').val()) {
                toast('开始日期 不能为空。');
                return false
            }
            if (!$('#end_date').val()) {
                toast('结束日期 不能为空。');
                return false
            }

            if (isLoading === false) {
                isLoading = true;

                axios.patch('{{ route('promotion.update','').'/' }}' + id + '', {
                    url: $('#url').val(),
                    single: $('#single').val(),
                    total: $('#total').val(),
                    state: $('#state').val(),
                    start_date: $('#start_date').val(),
                    end_date: $('#end_date').val(),
                })
                    .then(function (response) {
                        isLoading = false;
                        toast_tip2(response.data.message,'{{ route('promotion.index') }}');
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }
        }
    </script>
    </body>

@endsection
